package com.bym.mall.controller;

import com.bym.mall.service.IProductService;
import com.bym.mall.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品模块
 * </p>
 *
 * @author bym
 * @since 2022-03-26
 */
@Api("商品模块")
@RestController
@RequestMapping("/mall/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    /**
     * 商品列表
     *
     * @param categoryId 类别id
     * @param pageNum    页面num
     * @param pageSize   页面大小
     * @return {@link ResponseVo}
     */
    @ApiOperation("商品列表")
    @GetMapping("/list")
    public ResponseVo list(@RequestParam(required = false) Integer categoryId,
                           @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return productService.list(categoryId, pageNum, pageSize);
    }

    /**
     * 商品详情
     *
     * @param productId 商品id
     * @return {@link ResponseVo}
     */
    @ApiOperation("商品详情")
    @GetMapping("/detail")
    public ResponseVo detail(Integer productId) {
        return productService.detail(productId);
    }
}
